﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.Kinect.Nui;
using Coding4Fun.Kinect.Wpf;
using Blake.NUI.WPF.Utility;
using Kinductor.Gestures;
using Kinductor.Midi;
using System.Windows.Threading;

namespace Kinductor.ViewModels
{

    class KinductorController
    {
        public static Runtime nui = new Runtime();

        public static void LoadRuntimeParams() 
        {
            KinductorController.nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking);

            #region TransformSmooth
            //Must set to true and set after call to Initialize
            KinductorController.nui.SkeletonEngine.TransformSmooth = true;

            //Use to transform and reduce jitter
            var parameters = new TransformSmoothParameters
            {
                Smoothing = 1.0f,
                Correction = 0.0f,
                Prediction = 0.0f,
                JitterRadius = 0.05f,
                MaxDeviationRadius = 0.04f
            };

            nui.SkeletonEngine.SmoothParameters = parameters;

            #endregion
        }

        public static void UnloadKinect() {
            nui.Uninitialize();
        }

        public static void SetSkeletonDepth(Joint joint, out float x, out float y){
            KinductorController.nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out x, out y);
        }

        public static void OpenDepthStream(int poolSize) {
            KinductorController.nui.DepthStream.Open(ImageStreamType.Depth, poolSize, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);
        }
    }


}
